<?php
/**
 * 活动入口
 */
require_once dirname(dirname(__DIR__))."/common.php";
use app\cls\tom\Response;
use app\cls\tom\SysResource;
use app\cls\tom\Tools;
use app\cls\tom\Config;
use app\model\Activity;

//先从缓存里读取数据
$redis = SysResource::getRedis();
$redis_cache_key=REDIS_PREFIX."ACTIVITY_RUKOU_";
$redis_cache_data=$redis->get($redis_cache_key);
if($redis_cache_data){
    //读取缓存里的数据
    $data=json_decode($redis_cache_data);
    Response::output(0,"查询成功1",$data,count($data));
}else {

    try{


        //查询数据库
        $db = SysResource::getDB(false);
        $Activity=new Activity($db);
        //查询所有的活动
        $activity_rukou=$Activity->activity_rukou();
        if(empty($activity_rukou)){
            $activity_rukou=[];
        }
        $redis->setex($redis_cache_key,10,json_encode($activity_rukou));
        Response::output(0,"查询成功",$activity_rukou,count($activity_rukou));


    }catch(DBException $e){
        Response::output(-1,"系统忙碌中");
    }


}




